#include <stdio.h>
#include <stdlib.h>

typedef struct Student
{
	int iId;
	char caName[32];
	float fMathScore;
	float fMusicScore;
	float fDanceScore;
	float fSumScore;
}STU;
//void *:通用类型的指针，任何其他类型的指针可以直接赋给它
//使用时必须转换成其他有具体任性的指针
int comByScore(const void *s1, const void *s2)
{
	return ((STU*)s1)->fSumScore > ((STU*)s2)->fSumScore;
}

int comById(const void *s1, const void *s2)
{
	return ((STU*)s1)->iId < ((STU*)s2)->iId;
}

void display(const STU *stu, int count)
{
	if (NULL == stu || count <= 0)
	{
		return;
	}

	int i = 0;
	for (; i<count; i++)
	{
		printf("id:%d,name:%s\
math:%.1f,music:%.1f,dance:%.1f,total:%.1f\n"
               , stu[i].iId, stu[i].caName
			   , stu[i].fMathScore, stu[i].fMusicScore
			   , stu[i].fDanceScore, stu[i].fSumScore);
	}
}

int main(void)
{
	STU stu[5];
	int i = 0;
	for (; i<5; i++)
	{
		printf("请输入学生的信息id,name,math,music,dance:\n");
		scanf("%d%s%f%f%f", &stu[i].iId
						  , stu[i].caName
						  , &stu[i].fMathScore
						  , &stu[i].fMusicScore
						  , &stu[i].fDanceScore);
		stu[i].fSumScore = stu[i].fMathScore
				           +stu[i].fMusicScore
						   +stu[i].fDanceScore;
	}

	qsort(stu, 5, sizeof(STU), comByScore);
	display(stu, 5);
	printf("------------------\n\n");
	qsort(stu, 5, sizeof(STU), comById);
	display(stu, 5);

	return 0;
}
